App({
  //获取openid
  onLaunch: function() {
    var that = this;
    wx.login({
      success: function(res) {
        console.log(res)
        if (res.code) {
          var d = that.globalData; //这里存储了appid、secret、token串
          //获取openid
          var value = wx.getStorageSync('openid');
          //获取uid和name
          var uid = wx.getStorageSync('uid');
          var name = wx.getStorageSync('name');
          if (!value && !uid && !name) {
            //获取openid
            wx.request({
              url: "https://www.mamingwang.cn/api/openid/openid",
              data: {
                appid: d.appid,
                appsecret: d.secret,
                code: res.code,
              },
              method: "post",
              success: function(res) {
                wx.setStorage({
                  key: 'openid',
                  data: res.data.openid,
                })
                //获取uid和name
                wx.request({
                  url: 'https://www.mamingwang.cn/api/xinxi/uid',
                  data: {
                    openid: res.data.openid
                  },
                  method: "post",
                  success(res) {
                    wx.setStorage({
                      key: 'uid',
                      data: res.data.data.uid,
                    })
                    wx.setStorage({
                      key: 'name',
                      data: res.data.data.uname,
                    })
                  }
                })
              }
            });
          } else {
            that.openid = value;
            that.uid = uid;
            that.name = name;
          }
        } else {
          console.log('获取用户登录态失败！' + res.errMsg)
        }
      }
    });
  },
  globalData: {
    appid: 'wx6c1a86ee3e43e4a3', //appid
    secret: '32f54b415ab46d898b2714c327b8d4b9', //secret
  },
})